package com.doctor.adapter;

import java.util.List;

import com.doctor.adapter.KnowledgeThirdAdapter.ThirdClickCallback;
import com.doctor.bean.KnowledgeBean;
import com.doctor.ui.R;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.TextView;


public class KnowledgeSecAndThirdAdapter extends BaseAdapter{

	/**
	 * 医学知识二三级目录adapter
	 */
	
	private Context context;
	private List<List<KnowledgeBean>> beanList;
	private KnowledgeThirdAdapter thirdAdapter;
	private ThirdClickCallback callback;
	
	
	public KnowledgeSecAndThirdAdapter(Context context, List<List<KnowledgeBean>> beanList, ThirdClickCallback callback){
		super();
		this.context=context;
		this.beanList=beanList;
		this.callback=callback;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return beanList.size();
	}

	@Override
	public KnowledgeBean getItem(int arg0) {
		// TODO Auto-generated method stub
		return beanList.get(arg0).get(0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if (arg1==null) {
			holder=new ViewHolder();
			arg1=View.inflate(context, R.layout.knowledge_sec_list_item, null);
			holder.secondDir=(TextView) arg1.findViewById(R.id.secondDir);
			holder.gridView=(GridView) arg1.findViewById(R.id.gridView);
			
			arg1.setTag(holder);
		} else {
			holder=(ViewHolder) arg1.getTag();
		}
		
		KnowledgeBean secBean=getItem(arg0);
		holder.secondDir.setText(secBean.getDirname());
		
		thirdAdapter=new KnowledgeThirdAdapter(context, beanList.get(arg0), callback);
		holder.gridView.setAdapter(thirdAdapter);
		
		return arg1;
	}
	
	private class ViewHolder{
		TextView secondDir;
		GridView gridView;
	}
	


}
